package com.timoon.webcomponent.utility.navs.jd;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.request.resource.JavaScriptResourceReference;

import com.googlecode.wicket.jquery.ui.JQueryBehavior;
import com.googlecode.wicket.jquery.ui.Options;
import com.timoon.webcomponent.utility.navs.BaseNavPanel;
import com.timoon.webcomponent.utility.navs.NavParameter;

/**
 *<p>仿京东导航栏</p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class JdNavPanel extends BaseNavPanel {

	private List<NavParameter> navs;
	
	public JdNavPanel(String id, List<NavParameter> navs) {
		super(id, navs);
		// TODO Auto-generated constructor stub
	
		this.navs=navs;
		
		renderPanel();
	}

	private void renderPanel() {
		// TODO Auto-generated method stub
		
		renderNavs();
	}

	private void renderNavs() {
		// TODO Auto-generated method stub
		
		ListView<NavParameter> listView=new ListView<NavParameter>("wk_list",this.navs) {
			
			@Override
			protected void populateItem(ListItem<NavParameter> arg0) {
				// TODO Auto-generated method stub
				NavParameter parameter=arg0.getModelObject();
				
				BookmarkablePageLink link=new BookmarkablePageLink<>("wk_link",parameter.getTargetPage());
				arg0.add(link);
				
				link.add(new Label("wk_label",parameter.getText()));
			}
		};
		
		add(listView);
		
		//添加jquery动作
		add(new JdNavJqueryBehavior("#mainNav"));
	}
	
	private class JdNavJqueryBehavior extends JQueryBehavior{

		public JdNavJqueryBehavior(String selector) {
			super(selector, "jdnavpanel", new Options());
			// TODO Auto-generated constructor stub
			this.add(new JavaScriptResourceReference(this.getClass(), "jdnavpanel.js"));
		}
		
	}

}
